package com.example.demo.service.impl.gisImpl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.demo.common.result.Result;
import com.example.demo.model.DTO.GIsModel;
import com.example.demo.model.DTO.NameTypeDTO;
import com.example.demo.model.DTO.ParkingLotStatistics;
import com.example.demo.model.entity.GisEntity.Parking;
import com.example.demo.mapper.gisMapper.ParkingMapper;
import com.example.demo.service.ParkingService;
import com.example.demo.service.requestRvo.SimpleListRVO;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class ParkingImpl implements ParkingService {

    @Autowired
    ParkingMapper parkingMapper;
    @Override
    public Result listAll(SimpleListRVO vo){
        PageHelper.startPage(vo.getPageNumber(), vo.getPageSize());
        QueryWrapper<Parking> qw = new QueryWrapper<>();
        List<Parking> parkingList = parkingMapper.selectList(qw);
        List<GIsModel> gisModelList = parkingList.stream()
                .map(parking -> parking.toGIsModel("停车场",parking.getParkingLotName()))
                .collect(Collectors.toList());

        PageInfo<GIsModel> pageInfo = new PageInfo<>(gisModelList);
        return Result.okPageInfo(pageInfo);
    }

    @Override
    public Result getParkingLotStatistics(){
        List<ParkingLotStatistics> list = parkingMapper.getParkingLotStatistics();
        return Result.ok().data("data",list);
    }
    @Override
    public Result getParkinggroupByType(){
        List<NameTypeDTO> list = parkingMapper.getParkinggroupByType();
        QueryWrapper<Parking> qw = new QueryWrapper<>();
        Integer count = Math.toIntExact(parkingMapper.selectCount(qw));
        return Result.ok().data("data",list).data("total",count);
    }


}
